package action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.util.ValueStack;

import actionUtil.BaseAction;
import bean.UserBean;
import bean.UserParamBean;
import service.UserService;
import service.UserServiceImpl;

@ParentPackage(value="struts-default")
@Namespace(value="/")
@Action(value="configAction",results={
		
		@Result(name="config",location="/admin/user/config.jsp")
		
})
public class ConfigAction extends BaseAction implements ModelDriven<UserParamBean>{

	UserParamBean userParamBean=null;
	public UserParamBean getModel() {
		userParamBean=new UserParamBean();
		return userParamBean;
	}
	
	
	UserService userService=new UserServiceImpl();
	@Override
	public String execute() throws Exception {
		
		return null;
	}
	
	
	
	public String  load(){
	
		HttpSession session=request.getSession();
		UserBean userbean=null;
		int user_id=0;
		if(session.getAttribute("userbean") !=null ){
			userbean=(UserBean)session.getAttribute("userbean");
			user_id=userbean.getUser_id();
			
		}else{
			user_id=1;
		}
		
		
		this.userParamBean=userService.getParamBean(user_id);	
		ActionContext actionContext=ActionContext.getContext();
		ValueStack valueStack=actionContext.getValueStack();
		valueStack.push(this.userParamBean);
		actionContext.put("user_id", user_id);
	//	System.out.println("parambean="+parambean.getLeft_type());

		return "config";
	}

	
}
